<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>盒子居中</title>
    <style>
        .box1 {
            width: 400px;
            height: 400px;
            border: 1px solid #000;
            margin: 0 auto;
            /* 第1种 */
            display: flex;
            justify-content: center;
            align-items: center;
            /* 第2种 */
            /* position: relative; */
        }

        .box2 {
            width: 200px;
            height: 200px;
            background: rgb(145, 76, 76);
            /* 第2种 */
            /* position: absolute;
     top: 100px;
     left: 100px; */
            /* 第3种 */
            /* transform: translate(100px,100px); */
        }

        /* 圣杯布局 */
        .box3 {
            width: 100%;
            height: 50px;
            border: 1px solid #000;
            display: flex;
        }

        .box3 div {
            width: 50px;
            height: 50px;
            background-color: rgb(146, 15, 15);
            border: 1px solid #000;
        }

        .box4 {
            flex: 1;
            background-color: rgb(49, 165, 94);
        }
    </style>
</head>

<body>
    <!-- 盒子居中 -->
    <div class="box1">
        <div class="box2"></div>
    </div>
    <!-- 圣杯布局 -->
    <div class="box3">
        <div>左</div>
        <div class="box4">中</div>
        <div>右</div>
    </div>
</body>

</html>